The Dundas BI Rest services use with objects that belong to the Dundas.BI.WebApi.Models Namespace. When using .NET, these objects can be serialized, and deserialized by using JSON as the communication lanugage with the Dundas BI REST services.
The following example example demonstrates how to create a LogOnOptions object, serialize it as a JSON string, and then send it to the Dundas BI REST call for LogOn. This sample uses the Newtonsoft.Json library that is in the Dundas BI SDK folder.
using Dundas.BI.WebApi.Models;
using Newtonsoft.Json;
using System.Net.Http;
...
using (HttpClient httpClient = new HttpClient())
{
string logonUri = "http://localhost:8004/Api/LogOn/";
LogOnOptions logOnOptions = new LogOnOptions()
{
AccountName = "admin",
Password = "1234",
DeleteOtherSessions = true,
IsWindowsLogOn = false
};
// Serialize the logon options object.
string requestBodyAsString = JsonConvert.SerializeObject(logOnOptions);
// Prepare the request content
StringContent content =
new StringContent(
requestBodyAsString,
Encoding.UTF8,
"application/json"
);
string returnJsonString = string.Empty;
using (var response = httpClient.PostAsync(logonUri, content).Result)
{
returnJsonString =
response.Content.ReadAsStringAsync().Result;
}
}
The following example extends the previous example to recieve a JSON string, and serialize it to a LogOnResultData object.
using Dundas.BI.WebApi.Models;
using Newtonsoft.Json;
using System.Net.Http;
...
using (HttpClient httpClient = new HttpClient())
{
string logonUri = "http://localhost:8004/Api/LogOn/";
LogOnOptions logOnOptions = new LogOnOptions()
{
AccountName = "admin",
Password = "1234",
DeleteOtherSessions = true,
IsWindowsLogOn = false
};
// Serialize the logon options object.
string requestBodyAsString = JsonConvert.SerializeObject(logOnOptions);
// Prepare the request content
StringContent content =
new StringContent(
requestBodyAsString,
Encoding.UTF8,
"application/json"
);
string returnJsonString = string.Empty;
using (var response = httpClient.PostAsync(logonUri, content).Result)
{
returnJsonString =
response.Content.ReadAsStringAsync().Result;
}
LogOnResultData logOnResultData =
JsonConvert.DeserializeObject<LogOnResultData>(returnJsonString);
if(logOnResultData.LogOnFailureReason.Equals(Dundas.BI.AccountServices.LogOnFailureReason.None))
{
// LogOn was successful.
}
}